package com.openlab.service.basic.epidemic.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.openlab.service.basic.epidemic.dto.DetailDto;
import com.openlab.service.basic.epidemic.dto.ListInfo;
import com.openlab.service.basic.epidemic.entity.Epidemic;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface EpidemicMapper extends BaseMapper<Epidemic> {

    /**
     * 分页查询
     */
    @Select("<script> select SQL_CALC_FOUND_ROWS ejyy_epidemic.id id," +
            "            ejyy_epidemic.tour_code tour_code," +
            "            ejyy_epidemic.temperature temperature," +
            "            ejyy_epidemic.return_hometown return_hometown," +
            "            ejyy_epidemic.created_at created_at," +
            "            ejyy_building_info.type type," +
            "            ejyy_building_info.area area," +
            "            ejyy_building_info.building building," +
            "    ejyy_building_info.unit unit," +
            "    ejyy_building_info.number number " +
            "    from ejyy_epidemic  left join ejyy_building_info on ejyy_building_info.id=ejyy_epidemic.building_id " +
            "    where ejyy_epidemic.community_id=#{communityId} <when test = 'tourCode != null'> and ejyy_epidemic.tour_code = #{tourCode} </when>" +
            "    <when test = 'returnHometown != null'> and ejyy_epidemic.return_hometown = #{returnHometown} </when>" +
            "ORDER BY  ejyy_epidemic.id desc </script>")
    IPage<ListInfo> selectPageVo(@Param("page") IPage<ListInfo> page, @Param("communityId") Integer id,@Param("tourCode") Integer tourCode,@Param("returnHometown") Integer returnHometown);

    /**
     * 查询详情信息
     */
    @Select("select ejyy_epidemic.id," +
            "       ejyy_epidemic.building_id," +
            "       ejyy_epidemic.tour_code," +
            "       ejyy_epidemic.wechat_mp_user_id," +
            "       ejyy_epidemic.temperature," +
            "       ejyy_epidemic.return_hometown," +
            "       ejyy_epidemic.return_from_province," +
            "       ejyy_epidemic.return_from_city," +
            "       ejyy_epidemic.return_from_district," +
            "       ejyy_epidemic.created_by," +
            "       ejyy_epidemic.created_at," +
            "       ejyy_building_info.type," +
            "       ejyy_building_info.area," +
            "       ejyy_building_info.building," +
            "       ejyy_building_info.unit," +
            "       ejyy_building_info.number," +
            "       ejyy_wechat_mp_user.real_name as user_real_name," +
            "       ejyy_property_company_user.real_name as created_user_real_name" +
            "  from ejyy_epidemic left join ejyy_building_info on ejyy_building_info.id=ejyy_epidemic.building_id" +
            "  left join ejyy_wechat_mp_user on ejyy_wechat_mp_user.id=ejyy_epidemic.wechat_mp_user_id" +
            "  left join ejyy_property_company_user on ejyy_property_company_user.id=ejyy_epidemic.created_by" +
            "  where ejyy_epidemic.id=#{id} and ejyy_epidemic.community_id = #{community_id}")
    DetailDto selectDetail(@Param("id") Long id,@Param("community_id") Integer community_id);

    /**
     * 查询最后插入一行信息的id
     */
    @Select("select ejyy_epidemic.id from ejyy_epidemic where id=(select last_insert_id())")
    Integer findId();

    /*IPage<UserCarListDto> findList(IPage Page, @Param("community_id") Integer community_id, @Param("isNewEnergy") Integer isNewEnergy, @Param("carNumber") Integer carNumber, @Param("carType") Integer carType, @Param("status") Integer status, @Param("sync") Integer sync);*/

}
